package org.jeecg.modules.renyGj.controller;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.haikrlk.service.IAgHaikrlkService;
import org.jeecg.modules.hkvs.HaikService;
import org.jeecg.modules.renlzpsxt.entity.AgRenlzpsxt;
import org.jeecg.modules.renlzpsxt.entity.AgRenlzpsxtGuaid;
import org.jeecg.modules.renlzpsxt.service.IAgRenlzpsxtGuaidService;
import org.jeecg.modules.renlzpsxt.service.IAgRenlzpsxtService;
import org.jeecg.modules.renyGj.entity.AgRenygj;
import org.jeecg.modules.renyGj.entity.ResultPO;
import org.jeecg.modules.renyGj.service.IAgRenygjService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.renyGj.vo.RenygjxlGuaidVO;
import org.jeecg.modules.renygjxl.entity.Renygjxl;
import org.jeecg.modules.renygjxl.entity.RenygjxlGuaid;
import org.jeecg.modules.renygjxl.service.IRenygjxlGuaidService;
import org.jeecg.modules.renygjxl.service.IRenygjxlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

/**
 * @Description: 人员轨迹
 * @Author: jeecg-boot
 * @Date: 2020-10-27
 * @Version: V1.0
 */
@Api(tags = "人员轨迹")
@RestController
@RequestMapping("/renyGj/agRenygj")
@Slf4j
public class AgRenygjController extends JeecgController<AgRenygj, IAgRenygjService> {
    @Autowired
    private IAgRenygjService agRenygjService;

    @Autowired
    private IAgRenlzpsxtService agRenlzpsxtService;

    @Autowired
    private IAgRenlzpsxtGuaidService agRenlzpsxtGuaidService;

    @Autowired
    HaikService haikService;

    @Autowired
    private IAgHaikrlkService agHaikrlkService;


    // 人员聚集告警
    @GetMapping(value = "/renyjjgj")
    public Result<?> renyjjgj(String kaissj, String jiessj, String faz) {
        List list = agRenygjService.renyjjgj(kaissj, jiessj, faz);
        return Result.ok(list);
    }

    @GetMapping(value = "/list43d")
    public Object queryPageList43d(AgRenygj agRenygj,
                                      String zhuapsj_begin,String zhuapsj_end,
                                      @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                      @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                      HttpServletRequest req) {

        QueryWrapper<AgRenygj> queryWrapper = QueryGenerator.initQueryWrapper(agRenygj, req.getParameterMap());
        Page<AgRenygj> page = new Page<AgRenygj>(pageNo, pageSize);
        IPage<AgRenygj> pageList = agRenygjService.page(page, queryWrapper);

        return agRenygjService.getResult(pageList);
    }

    /**
     * 分页列表查询
     *
     * @param agRenygj
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @AutoLog(value = "人员轨迹-分页列表查询")
    @ApiOperation(value = "人员轨迹-分页列表查询", notes = "人员轨迹-分页列表查询")
    @GetMapping(value = "/list")
    public Result<?> queryPageList(AgRenygj agRenygj,
                                   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                   HttpServletRequest req) {

        QueryWrapper<AgRenygj> queryWrapper = QueryGenerator.initQueryWrapper(agRenygj, req.getParameterMap());
        queryWrapper.isNotNull("renybh");

        Page<AgRenygj> page = new Page<AgRenygj>(pageNo, pageSize);
        IPage<AgRenygj> pageList = agRenygjService.page(page, queryWrapper);
        return Result.ok(pageList);
    }

    @GetMapping(value = "/list2")
    public Result<?> queryPageList2(AgRenygj agRenygj,
                                   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                   HttpServletRequest req) {

        QueryWrapper<AgRenygj> queryWrapper = QueryGenerator.initQueryWrapper(agRenygj, req.getParameterMap());
        queryWrapper.isNull("renybh");

        Page<AgRenygj> page = new Page<AgRenygj>(pageNo, pageSize);
        IPage<AgRenygj> pageList = agRenygjService.page(page, queryWrapper);
        return Result.ok(pageList);
    }

    /**
     * 添加
     *
     * @param agRenygj
     * @return
     */
    @AutoLog(value = "人员轨迹-添加")
    @ApiOperation(value = "人员轨迹-添加", notes = "人员轨迹-添加")
    @PostMapping(value = "/add")
    public Result<?> add(@RequestBody AgRenygj agRenygj) {
        agRenygjService.save(agRenygj);
        return Result.ok("添加成功！");
    }

    /**
     * 编辑
     *
     * @param agRenygj
     * @return
     */
    @AutoLog(value = "人员轨迹-编辑")
    @ApiOperation(value = "人员轨迹-编辑", notes = "人员轨迹-编辑")
    @PutMapping(value = "/edit")
    public Result<?> edit(@RequestBody AgRenygj agRenygj) {
        agRenygjService.updateById(agRenygj);
        return Result.ok("编辑成功!");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "人员轨迹-通过id删除")
    @ApiOperation(value = "人员轨迹-通过id删除", notes = "人员轨迹-通过id删除")
    @DeleteMapping(value = "/delete")
    public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
        agRenygjService.removeById(id);
        return Result.ok("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "人员轨迹-批量删除")
    @ApiOperation(value = "人员轨迹-批量删除", notes = "人员轨迹-批量删除")
    @DeleteMapping(value = "/deleteBatch")
    public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.agRenygjService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.ok("批量删除成功!");
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @AutoLog(value = "人员轨迹-通过id查询")
    @ApiOperation(value = "人员轨迹-通过id查询", notes = "人员轨迹-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<?> queryById(@RequestParam(name = "id", required = true) String id) {
        AgRenygj agRenygj = agRenygjService.getById(id);
        if (agRenygj == null) {
            return Result.error("未找到对应数据");
        }
        return Result.ok(agRenygj);
    }

    /**
     * 导出excel
     *
     * @param request
     * @param agRenygj
     */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, AgRenygj agRenygj) {
        return super.exportXls(request, agRenygj, AgRenygj.class, "人员轨迹");
    }

    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, AgRenygj.class);
    }

}
